package com.xinzhitong.www.controller;

import com.xinzhitong.www.exception.visitor.NullNewsOutlineException;
import com.xinzhitong.www.exception.visitor.NullProfessionInformationException;
import com.xinzhitong.www.service.VisitorService;
import com.xinzhitong.www.utils.Message;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 游客控制器
 *
 * @author 魏骆淳
 */
@CrossOrigin
@RestController
@RequestMapping("visitor")
public class VisitorController {

    @Resource
    private VisitorService visitorService;

    /**
     * 获取工种信息
     *
     * @return 工种信息
     */
    @RequestMapping(value = "getProfessionInformation", method = RequestMethod.GET)
    public Message positionInformation() {
        try {
            return Message.createSuc(visitorService.getProfessionInformation());
        } catch (NullProfessionInformationException e) {
            e.printStackTrace();
            return Message.createErr("工种为空");
        }
    }

    /**
     * 获取新闻轮播图
     *
     * @return 新闻概要
     */
    @RequestMapping(value = "getNewsOutline", method = RequestMethod.GET)
    public Message newsOutline() {
        try {
            return Message.createSuc(visitorService.getNewsOutline());
        } catch (NullNewsOutlineException e) {
            e.printStackTrace();
            return Message.createErr("新闻概要为空");
        }
    }

}
